const global = getApp().globalData;
const util = global.util;
Component({
  data: {
    timetext: '00:00:00'
  },
  properties: {
    start: {
      type: Boolean,
      value: false,
      observer: "_startObserver"
    },
    interval: {
      type: Number,
      value: 10
    }
  },
  attached() {
    console.log( this.data );
  },
  methods: {
    _startObserver( val ) {
      if ( val ) {
        this.startTimer();
      } else {
        this.clearTimer();
      }
    },
    startTimer() {
      let self = this;
      let interval = this.data.interval;
      this.msec = 0;
      this.timer = setInterval( () => {
        self.msec += interval;
        self.setTimetext( this.msec );
      }, interval )
    },
    clearTimer() {
      clearInterval( this.timer );
      this.timer = null;
    },
    setTimetext( msec ) {
      let time = util.msecFormat( msec );
      time = time.minute + ':' + time.second + '.' + time.ms;
      this.setData({
        timetext: time
      })
    }
  }
})